from time import sleep
from selenium import webdriver

# 打开浏览器-创建浏览器对象
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By

# 打开浏览器
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.select import Select
driver = webdriver.Chrome(executable_path='chromedriver.exe')

# 输入访问地址（URL）
driver.get("http://121.43.169.97:8848/pageA.html")
# driver = webdriver.Chrome()

# 放大浏览器
driver.maximize_window()

# ---------------------------下标/索引------------------------------
#需求：使用‘注册A.html’页面，完成对城市的下拉框的操作
# 1）.选择‘广州′
# 2).暂停2秒，选择′上海′
#3）.暂停2秒，选择′北京’
el = driver.find_element_by_css_selector("#selectA")
select = Select(el)
sleep(2)

# 1）.选择‘广州′
select.select_by_value("gz")

# 2).暂停2秒，选择′上海′
sleep(2)
select.select_by_index(1)
sleep(2)

#3）.暂停2秒，选择′北京’
sleep(2)
select.select_by_index(0)



# ---------------------------value值实现--------------------------

# # 1）.选择‘广州′
select.select_by_value("gz")

#  2).暂停2秒，选择′上海′
sleep(2)
select.select_by_value("sh")
sleep(2)

# #3）.暂停2秒，选择′北京’
sleep(2)
select.select_by_value("bj")




# ---------------------------文本值值实现---------------------------

# 1）.选择‘广州′
select.select_by_visible_text("广州")

# 2).暂停2秒，选择′上海′
sleep(2)
select.select_by_visible_text("上海")
sleep(2)

#3）.暂停2秒，选择′北京’
sleep(2)
select.select_by_visible_text("北京")

sleep(2)
driver.quit()